using System;
using System.Runtime.InteropServices;

namespace Framework.Interop
{
    internal static class User32
    {
        /// <summary>
        /// Inserts a new menu item at the specified position in a menu.
        /// </summary>
        /// <param name="hMenu">A handle to the menu in which the new menu item is inserted.</param>
        /// <param name="uItem">The identifier or position of the menu item before which to insert the new item. The meaning of this parameter depends on the value of <see cref="fByPosition">fByPosition</see>.</param>
        /// <param name="fByPosition">Controls the meaning of <see cref="uItem">uItem</see>. If this parameter is FALSE, <see cref="uItem">uItem</see> is a menu item identifier. Otherwise, it is a menu item position. See <see cref="http://msdn.microsoft.com/en-us/library/ms647553.aspx#accessing_menu_items_programmatically">Accessing Menu Items Programmatically</see> for more information.</param>
        /// <param name="lpmii">A pointer to a <see cref="MenuItemInfo">MenuItemInfo</see> structure that contains information about the new menu item.</param>
        /// <returns>
        /// If the function succeeds, the return value is nonzero.
        /// If the function fails, the return value is zero. To get extended error information, use the <see cref="Marshal.GetLastWin32Error">GetLastError</see> function.
        /// </returns>
        /// <seealso>
        /// Native <see cref="http://msdn.microsoft.com/en-us/library/ms647988.aspx">method</see>
        /// </seealso>
        [DllImport("user32.dll", SetLastError = true)]
        internal static extern bool InsertMenuItem(IntPtr hMenu, uint uItem, bool fByPosition, ref MenuItemInfo lpmii);

        /// <summary>
        /// Changes information about a menu item.
        /// </summary>
        /// <param name="hMenu">A handle to the menu that contains the menu item.</param>
        /// <param name="uItem">The identifier or position of the menu item  to change. The meaning of this parameter depends on the value of <see cref="fByPosition">fByPosition</see>.</param>
        /// <param name="fByPosition">The meaning of <see cref="uItem">uItem</see>. If this parameter is FALSE, uItem is a menu item identifier. Otherwise, it is a menu item position. See <see cref="http://msdn.microsoft.com/en-us/library/ms647553.aspx">About Menus</see> for more information.</param>
        /// <param name="lpmii">A pointer to a <see cref="MenuItemInfo">MenuItemInfo</see> structure that contains information about the menu item and specifies which menu item attributes to change.</param>
        /// <returns>
        /// If the function succeeds, the return value is nonzero.
        /// If the function fails, the return value is zero. To get extended error information, use the <see cref="Marshal.GetLastWin32Error">GetLastError</see> function.
        /// </returns>
        /// <seealso>
        /// Native <see cref="http://msdn.microsoft.com/en-us/library/ms648001.aspx">method</see>
        /// </seealso>
        [DllImport("user32.dll", SetLastError = true)]
        internal static extern bool SetMenuItemInfo(IntPtr hMenu, uint uItem, bool fByPosition, ref MenuItemInfo lpmii);

        /// <summary>
        /// Determines whether a value is an integer identifier for a resource.
        /// </summary>
        /// <param name="p">The integer value to be tested.</param>
        /// <returns>
        /// If the value is a resource identifier, the return value is TRUE. Otherwise, the return value is FALSE.
        /// </returns>
        /// <seealso>
        /// Native <see cref="http://msdn.microsoft.com/en-us/library/ms648028.aspx">macro</see>
        /// </seealso>
        internal static bool IsIntResource(IntPtr p)
        {
            return (((uint)p) >> 16) == 0;
        }
    } ;
}
